package city.spring.modules.work.action.handler;

import city.spring.modules.work.action.model.AbstractPlanShift;
import city.spring.modules.work.action.model.AbstractPlanUser;
import city.spring.modules.work.action.model.ResultItem;
import com.google.common.collect.Table;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

/**
 * 昨天特殊班次是否存在该人员
 *
 * @author HouKunLin
 * @date 2020/6/5 0005 13:59
 */
public class YesterdayHasPeopleHandler<SHIFT, USER> implements IHandler<SHIFT, USER> {
    @Override
    public boolean run(Table<LocalDate, Object, ResultItem<SHIFT, USER>> resultTable, LocalDate rowKey, Object colKey, AbstractPlanUser<USER> people) {
        Map<Object, ResultItem<SHIFT, USER>> yesterday = resultTable.rowMap().get(rowKey.minusDays(1));
        if (yesterday == null) {
            return false;
        }
        for (Map.Entry<Object, ResultItem<SHIFT, USER>> colMap : yesterday.entrySet()) {
            ResultItem<SHIFT, USER> item = colMap.getValue();
            List<AbstractPlanUser<USER>> users = item.getUsers();
            AbstractPlanShift<SHIFT> shift = item.getShift();
            if (shift.isTomorrowNotWork() && users.contains(people)) {
                return true;
            }
        }
        return false;
    }
}
